<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

	<title>Dijit Tree Test (steel)</title>

	<link rel="stylesheet" href="../../../../dojo/dojo/resources/dojo.css">
	<link rel="stylesheet" href="../../../../dojo/dijit/tests/css/dijitTests.css">
	<style type="text/css">
	.widgetContainer {
		padding-top: 10px;
	}
	.testTitle {
		padding-bottom: 10px;
	}
	
	body {
		padding-top: 60px;
	}
	
	</style>

	<!-- required: a default dijit theme: -->
	<link id="themeStyles" rel="stylesheet" href="../../themes/steel/SteelBase.css">

	<!-- required: dojo.js -->
	<script type="text/javascript" src="../../../../dojo/dojo/dojo.js"
		djConfig="parseOnLoad: true, isDebug: true"></script>

	<!-- not needed, for testing alternate themes -->
	<script type="text/javascript" src="../../../../dojo/dijit/tests/_testCommon.js"></script>

	<script language="JavaScript" type="text/javascript">
		dojo.require("dojo.data.ItemFileReadStore");
		dojo.require("dijit.dijit"); // optimize: load dijit layer
		dojo.require("dijit.Tree");
		dojo.require("dijit.tree.ForestStoreModel");
		dojo.require("dijit.ColorPalette");
		dojo.require("dijit.Menu");
		dojo.require("dojo.parser");	// scan page for widgets and instantiate them

		dojo.addOnLoad(function(){

		});

		function myHandler(id,newValue){
			console.debug("onChange for id = " + id + ", value: " + newValue);
		}
	</script>

</head>
<body class="steel">
<div class="widgetContainer" style="width: 50%;">
	<h3 class="testDialog">Dijit Dialog Test</h3>
		<div dojoType="dojo.data.ItemFileReadStore" jsId="continentStore"
		url="data/countries.json"></div>
	<div dojoType="dijit.tree.ForestStoreModel" jsId="continentModel"
		store="continentStore" query="{type:'continent'}"
		rootId="continentRoot" rootLabel="Continents" childrenAttrs="children"></div>

	<h3>Tree with hardcoded root node (not corresponding to any item in the store)</h3>
	<p>
		Clicking a folder node will open/close it (openOnclick==true),
		and clicking a leaf node will log a message to the console.
	</p>

	<div dojoType="dijit.Tree" id="mytree" model="continentModel" openOnClick="true" onLoad="console.log('loaded mytree (first tree)');">
		<script type="dojo/method" event="onClick" args="item">
			console.log("Execute of node " + continentStore.getLabel(item)
				+", population=" + continentStore.getValue(item, "population"));
		</script>
		<script type="dojo/method" event="onOpen" args="item">
			console.log("Open of node " + continentStore.getLabel(item)||"root");
		</script>
		<script type="dojo/method" event="onClose" args="item">
			console.log("Close of node " + continentStore.getLabel(item)||"root");
		</script>
	</div>
	<!-- <button onclick="dijit.byId('mytree').destroyRecursive();">destroy</button> -->
</div>
<div class="widgetContainer" style="width: 50%;">
	<h3>A rootless tree (no "continents" node) with context menus, and custom icons</h3>
	<ul dojoType="dijit.Menu" id="tree_menu" style="display: none;">
		<li dojoType="dijit.MenuItem" onClick="console.log('Hello world');">Enabled Item</li>
		<li dojoType="dijit.MenuItem" disabled="true">Disabled Item</li>
		<li dojoType="dijit.MenuItem" iconClass="dijitEditorIcon dijitEditorIconCut"
			onClick="console.log('not actually cutting anything, just a test!')">Cut</li>
		<li dojoType="dijit.MenuItem" iconClass="dijitEditorIcon dijitEditorIconCopy"
			onClick="console.log('not actually copying anything, just a test!')">Copy</li>
		<li dojoType="dijit.MenuItem" iconClass="dijitEditorIcon dijitEditorIconPaste"
			onClick="console.log('not actually pasting anything, just a test!')">Paste</li>
		<li dojoType="dijit.PopupMenuItem">
			<span>Enabled Submenu</span>
			<ul dojoType="dijit.Menu" id="submenu2">
				<li dojoType="dijit.MenuItem" onClick="console.log('Submenu 1!')">Submenu Item One</li>
				<li dojoType="dijit.MenuItem" onClick="console.log('Submenu 2!')">Submenu Item Two</li>
				<li dojoType="dijit.PopupMenuItem">

					<span>Deeper Submenu</span>
					<ul dojoType="dijit.Menu" id="submenu4">
						<li dojoType="dijit.MenuItem" onClick="console.log('Sub-submenu 1!')">Sub-sub-menu Item One</li>
						<li dojoType="dijit.MenuItem" onClick="console.log('Sub-submenu 2!')">Sub-sub-menu Item Two</li>
					</ul>
				</li>
			</ul>

		</li>
		<li dojoType="dijit.PopupMenuItem" disabled="true">
			<span>Disabled Submenu</span>
			<ul dojoType="dijit.Menu" id="submenu3" style="display: none;">
				<li dojoType="dijit.MenuItem" onClick="console.log('Submenu 1!')">Submenu Item One</li>
				<li dojoType="dijit.MenuItem" onClick="console.log('Submenu 2!')">Submenu Item Two</li>
			</ul>

		</li>
	</ul>
	<div dojoType="dijit.Tree" id="tree2"
		model="continentModel" showRoot="false" openOnClick="true"onLoad="console.log('loaded tree2 (second tree)');">

		<script type="dojo/connect">
			var menu = dijit.byId("tree_menu");
			// when we right-click anywhere on the tree, make sure we open the menu
			menu.bindDomNode(this.domNode);

			dojo.connect(menu, "_openMyself", this, function(e){
				// get a hold of, and log out, the tree node that was the source of this open event
				var tn = dijit.getEnclosingWidget(e.target);
				console.debug(tn);

				// now inspect the data store item that backs the tree node:
				console.debug(tn.item);

				// contrived condition: if this tree node doesn't have any children, disable all of the menu items
				dojo.forEach(menu.getChildren(), function(i){ i.set('disabled', !tn.item.children); });

				// IMPLEMENT CUSTOM MENU BEHAVIOR HERE
			});
		</script>
		<script type="dojo/method" event="getIconClass" args="item, opened">
           return (item == this.model.root || continentStore.getValue(item, "type") == "continent") ?
                   (opened ? "customFolderOpenedIcon" : "customFolderClosedIcon") :
                    "noteIcon";
		</script>
		<script type="dojo/method" event="onClick" args="item">
			console.log("Execute of node " + this.model.getLabel(item)
				+", population=" + continentStore.getValue(item, "population"));
		</script>
	</div>
</div>

</body>
</html>